package flyshoes.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import flyshoes.utils.ThreadLocalUtil;
import org.springframework.context.annotation.Bean;

//在微服务之间传递user-info
public class OpenFeignConfig {
   @Bean
    public RequestInterceptor IdFeignInfoInterceptor(){
       return new RequestInterceptor() {
           @Override
           public void apply(RequestTemplate requestTemplate) {
               Long userId = ThreadLocalUtil.get();
               if (userId != null){
                   requestTemplate.header("user-info",userId.toString());
               }
           }
       };
   }
}
